﻿using DalatCooking.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class UserControls_Search : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected override void OnInit(EventArgs e)
    {
        Page.Title = "Tìm kiếm";
        BinData();
        base.OnInit(e);
    }
    void BinData()
    {
        int total;
        rptSearch.DataSource = CourseManager.FindByKeyword(5, 1, out total, Keyword);
        rptSearch.DataBind();
    }
    public string Keyword
    {
        get
        {
            if (Server.HtmlEncode(Request.QueryString["q"]) != null)
                return Server.HtmlEncode(Request.QueryString["q"]);
            else return string.Empty;
        }
    }
    public List<Course> PagingSearch(int pageSize, int pageNum, out int totalRowCount, string keywrod)
    {
        var query = from c in CourseManager.FindAll()
                    where c.Name.Contains(keywrod)
                    select c;
        totalRowCount = query.Count();
        var list = query.Skip(pageSize * (pageNum - 1)).Take(pageSize).ToList();
        return list;
    }
}